<%@ page contentType="text/html; charset=UTF-8"%>
<%@page import="edu.ccut.saturn.component.SaturnData"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/extjs/include/all.jsp"%>
<title></title>
<script type="text/javascript">
	var userId = '${__SATURN_AUTORITY_USER__.id}';
	var workitem_id = '<%=request.getParameter("workitem_id")%>';
	Ext.onReady(function(){
		var resultWidth = Ext.get("task-grid").getWidth();
		var store = new Ext.data.JsonStore({
		    url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.client::/myTaskModule/action/QueryWorkitemOpMesg.action',
		    root: 'result',
		    totalProperty:'count',
		    fields: [
	               {name: 'time', mapping: 'time'},
	               {name: 'operate_type', mapping: 'operate_type'},
		    	   {name: 'content', mapping: 'content'},
	               {name: 'message_from', mapping: 'message_from'}
	           ]
		});
	  
	    var grid = new Ext.grid.GridPanel({
       	    store: store,
	        columns: [
	       	    {header: "时间", width:resultWidth*0.2, dataIndex: 'time', sortable: true},
	            {header: "操作类型", width: resultWidth*0.1, dataIndex: 'operate_type', sortable: true,renderer:showType},
	            {header: "内容", width: resultWidth*0.2, dataIndex: 'content', sortable: true},
	            {header: "信息来源", width: resultWidth*0.1, dataIndex: 'message_from', sortable: true}
	        ],
	        renderTo:'task-grid',
	        height:230,
	        width:resultWidth,
	        collapsible:true,
	        loadMask: {msg:'正在加载数据，请稍侯……'}, 
	        frame:true,
	        title:'工作项操作信息'
    	});
   
   	store.load({params: {start:0,limit:20,workitem_id:workitem_id}});
 	
    store.on('beforeload',function(){
		 	Ext.apply(this.baseParams,{workitem_id:workitem_id});       
    });
    
   
    var workitemStore = new Ext.data.JsonStore({
		    url: '${pageContext.request.contextPath}/edu.ccut.saturn.workflow.client::/myTaskModule/action/QueryWorkitemById.action',
		    root: 'result',
		    fields: [
	               {name: 'workitem_id', mapping: 'workitem_id'},
	               {name: 'name', mapping: 'name'},
	               {name: 'priority', mapping: 'priority'},
	               {name: 'state', mapping: 'state'},
	               {name: 'process_instance_name', mapping: 'process_instance_name'},
	               {name: 'description', mapping: 'description'},
	               {name: 'is_timeout', mapping: 'is_timeout'},
	               {name: 'timeout_number', mapping: 'timeout_number'}
	           ]
		});
		
	 workitemStore.load({params: {workitem_id:workitem_id}});
	 
     workitemStore.on('load',function(){
  	     var simple = new Ext.FormPanel({
			renderTo:'form-ct',
	        frame:true,
	        title: '工作项详细信息',
	        collapsible:true,
	        bodyStyle:'width:100%',
	        autoHeight:true,
	        labelWidth:resultWidth*0.1,
	        items: [{
	            layout:'column',
	            items:[{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '工作项ID',
		                    name: 'workitem_id',
		                    id: 'workitem_id',
		                    value:workitemStore.getAt(0).data["workitem_id"],
		                    disabled:true
		                },{
		                    xtype:'textfield',
		                    fieldLabel: '流程实例名称',
		                    name: 'process_instance_name',
		                    id: 'process_instance_name',
		                    value:workitemStore.getAt(0).data["process_instance_name"],
		                    disabled:true
		                }]
	            },{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '工作项名称',
		                    name: 'name',
		                    id: 'name',
		                    value:workitemStore.getAt(0).data["name"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '工作项描述',
		                    name: 'description',
		                    id: 'description',
		                     value:workitemStore.getAt(0).data["description"],
		                     disabled:true
		                }]
	            	},{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '优先级',
		                    name: 'priority',
		                    id: 'priority',
		                    value:workitemStore.getAt(0).data["priority"],
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '是否超时',
		                    name: 'is_timeout',
		                    id: 'is_timeout',
		                    value:showIsTimeout(workitemStore.getAt(0).data["is_timeout"]),
		                    disabled:true
		                }]
	            	},{
	                columnWidth:.5,
	                layout: 'form',
	                items: [{
		                    xtype:'textfield',
		                    fieldLabel: '当前状态',
		                    name: 'state',
		                    id: 'state',
		                    value:workitemStore.getAt(0).data["state"]==12?"完成":"运行",
		                    disabled:true
		                }, {
		                    xtype:'textfield',
		                    fieldLabel: '超时数',
		                    name: 'timeout_number',
		                    id: 'timeout_number',
		                    value:getNumber(workitemStore.getAt(0).data["timeout_number"]),
		                    disabled:true
		                }]
	            	}] 
       			}],
       		buttons: [{
	            text: '返回',
	            handler:function(){
	            	window.history.back();
	            }
       		 }]	
        })
     });
     
     function getNumber(timeout_number){
	      	if(timeout_number==""||timeout_number=="0"){
	      		return "暂无";
	      	}else{
	      		return timeout_number;
	      	}
     }
    
    function showIsTimeout(is_timeout){
    	if(is_timeout=="Y"){
    		return "是";
    	}else{
    		return "否";
    	}
    }
      
     function showType(value){
     	if(value=='1'){
     		return '代理';
     	}
     	else if(value=='2'){
     		return '代办';
     	}
     	else if(value=='3'){
     		return '协办';
     	}
     	else if(value=='4'){
     		return '待确认';
     	}
     	else if(value=='5'){
     		return '拒绝';
     	}
     	else if(value=='6'){
     		return '重做';
     	}
     	else if(value=='7'){
     		return '收回';
     	}
     }
});
</script>
<div id='task-grid' width='100%'></div>
<div id='form-ct' width='100%'></div>

</head>
</html>